package sg.edu.nus.iss.billing.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;


public class PropertiesRead {

	/** Contains the Rate properties */
	private Properties props;

	/**
	 * Constructs a new BillRate
	 */
	public PropertiesRead() {
		props = new Properties();
	}


	/**
	 * Searches for the property with the specified key in this property list. The method returns
	 * null if the property is not found.
	 * 
	 * @param key
	 *                The property key
	 * 
	 * @return The value in this property list with the specified key value
	 */
	public String getProperty(String key) {
		if (key == null) {
			return null;
		}
		return props.getProperty(key);
	}

	/**
	 * Searches for the property with the specified key in this property list. The method returns
	 * the default value argument if the property is not found.
	 * 
	 * @param key
	 *                The property key
	 * @param defaultValue
	 *                A default value
	 * 
	 * @return The value in this property list with the specified key value
	 */
	public String getProperty(String key, String defaultValue) {
		if (key == null) {
			return null;
		}
		return props.getProperty(key, defaultValue);
	}

	/**
	 * Reads a property list (key and element pairs) from the input stream.
	 * 
	 * @param is
	 *                The input stream
	 * 
	 * @exception If
	 *                    an error occurred when reading from the input stream
	 */
	public void load(InputStream is) throws IOException {
		props.load(is);
	}
}

